package org.jeecg.modules.online.cgform.converter.p011b;

import com.alibaba.fastjson.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.converter.FieldCommentConverter;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;
import org.jetbrains.annotations.NotNull;

/* renamed from: org.jeecg.modules.online.cgform.converter.b.b */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/converter/b/b.class */
public class DateFormatConverter implements FieldCommentConverter {

    /* renamed from: a */
    String f179a;

    /* renamed from: b */
    private static final String f180b = "year";

    /* renamed from: d */
    private static final String f182d = "month";

    /* renamed from: f */
    private static final String f184f = "week";

    /* renamed from: g */
    private static final String f185g = "quarter";

    /* renamed from: h */
    private static final String f186h = "default";

    /* renamed from: c */
    private static final SimpleDateFormat f181c = new SimpleDateFormat("yyyy");

    /* renamed from: e */
    private static final SimpleDateFormat f183e = new SimpleDateFormat("yyyy-MM");

    /* renamed from: i */
    private static final List<InterfaceC0009b> f187i = new ArrayList();

    /* JADX INFO: Access modifiers changed from: package-private */
    /* compiled from: DateFormatConverter.java */
    /* renamed from: org.jeecg.modules.online.cgform.converter.b.b$b */
    /* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/converter/b/b$b.class */
    public interface InterfaceC0009b {
        /* renamed from: b */
        boolean mo392b(String str);

        /* renamed from: a */
        Date mo391a(String str) throws ParseException;
    }

    static {
        f187i.add(new C0010c("^\\d{4}$", "yyyy"));
        f187i.add(new C0010c("^\\d{4}年$", "yyyy年"));
        f187i.add(new C0010c("^\\d{4}年\\d{1,2}月$", "yyyy年MM月"));
        f187i.add(new C0010c("^\\d{4}-\\d{1,2}$", "yyyy-MM"));
        f187i.add(new C0010c("^\\d{4}\\/\\d{1,2}$", "yyyy/MM"));
        f187i.add(new AbstractC0008a("^\\d{4}-\\d{1,2}周$") { // from class: org.jeecg.modules.online.cgform.converter.b.b.1
            @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
            /* renamed from: a */
            public Date mo391a(String str) {
                return DateFormatConverter.m393b(Integer.parseInt(str.substring(0, str.indexOf("-"))), Integer.parseInt(str.substring(str.indexOf("-") + 1, str.indexOf("周"))));
            }
        });
        f187i.add(new AbstractC0008a("^\\d{4}年\\d{1,2}周$") { // from class: org.jeecg.modules.online.cgform.converter.b.b.2
            @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
            /* renamed from: a */
            public Date mo391a(String str) {
                return DateFormatConverter.m393b(Integer.parseInt(str.substring(0, str.indexOf("年"))), Integer.parseInt(str.substring(str.indexOf("年") + 1, str.indexOf("周"))));
            }
        });
        f187i.add(new AbstractC0008a("^\\d{4}-Q\\d{1}$") { // from class: org.jeecg.modules.online.cgform.converter.b.b.3
            @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
            /* renamed from: a */
            public Date mo391a(String str) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(1, Integer.parseInt(str.substring(0, str.indexOf("-"))));
                calendar.set(2, (Integer.parseInt(str.substring(str.indexOf("-Q") + 2)) * 3) - 1);
                return calendar.getTime();
            }
        });
        f187i.add(new AbstractC0008a("^\\d{4}年Q\\d{1}$") { // from class: org.jeecg.modules.online.cgform.converter.b.b.4
            @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
            /* renamed from: a */
            public Date mo391a(String str) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(1, Integer.parseInt(str.substring(0, str.indexOf("年"))));
                calendar.set(2, (Integer.parseInt(str.substring(str.indexOf("年Q") + 2)) * 3) - 1);
                return calendar.getTime();
            }
        });
        f187i.add(new AbstractC0008a("^\\d{4}年\\d{1}季度$") { // from class: org.jeecg.modules.online.cgform.converter.b.b.5
            @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
            /* renamed from: a */
            public Date mo391a(String str) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(1, Integer.parseInt(str.substring(0, str.indexOf("年"))));
                calendar.set(2, (Integer.parseInt(str.substring(str.indexOf("年") + 1, str.indexOf("季度"))) * 3) - 1);
                return calendar.getTime();
            }
        });
        f187i.add(new C0010c("^\\d{4}-\\d{1,2}-\\d{1,2}$", "yyyy-MM-dd"));
        f187i.add(new C0010c("^\\d{4}年\\d{1,2}月\\d{1,2}日$", "yyyy年MM月dd日"));
    }

    /* JADX INFO: Access modifiers changed from: private */
    @NotNull
    /* renamed from: b */
    public static Date m393b(int i, int i2) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(i, 0, 1);
        int i3 = calendar.get(7);
        if (i3 > 3) {
            i3 = 9 - i3;
        }
        calendar.set(6, i3);
        calendar.add(6, (i2 - 1) * 7);
        return calendar.getTime();
    }

    public DateFormatConverter(OnlCgformField onlCgformField) {
        String fieldExtendJson = onlCgformField.getFieldExtendJson();
        if (oConvertUtils.isNotEmpty(fieldExtendJson)) {
            JSONObject parseObject = JSONObject.parseObject(fieldExtendJson);
            if (parseObject.containsKey("picker") && null != parseObject.get("picker")) {
                this.f179a = parseObject.getString("picker");
            }
        }
    }

    @Override // org.jeecg.modules.online.cgform.converter.FieldCommentConverter
    public String converterToVal(String txt) {
        if (null == this.f179a || this.f179a.isEmpty()) {
            return txt;
        }
        if (null == txt || txt.isEmpty()) {
            return txt;
        }
        Date m394a = m394a(txt);
        if (null == m394a) {
            return "";
        }
        return ((SimpleDateFormat) DateUtils.date_sdf.get()).format(m394a);
    }

    /* renamed from: a */
    private Date m394a(String str) {
        for (InterfaceC0009b interfaceC0009b : f187i) {
            if (interfaceC0009b.mo392b(str)) {
                try {
                    return interfaceC0009b.mo391a(str);
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return null;
    }

    @Override // org.jeecg.modules.online.cgform.converter.FieldCommentConverter
    public String converterToTxt(String val) {
        if (null == this.f179a || this.f179a.isEmpty()) {
            return val;
        }
        if (null == val || val.isEmpty()) {
            return val;
        }
        Date parse = null;
		try {
			parse = ((SimpleDateFormat) DateUtils.date_sdf.get()).parse(val);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        String str = this.f179a;
        boolean z = true;
        switch (str) {
            case "week":
            	 Calendar calendar = Calendar.getInstance();
                 calendar.setFirstDayOfWeek(1);
                 calendar.setTime(parse);
                 int i = calendar.get(1);
                 if (this.f179a.equals(f184f)) {
                     calendar.set(i, 0, 1);
                     int i2 = calendar.get(7);
                     if (i2 > 3) {
                         i2 = 8 - i2;
                     }
                     calendar.setTime(parse);
                     return String.format("%d-%d周", Integer.valueOf(i), Integer.valueOf(((calendar.get(6) - i2) / 7) + 1));
                 }
                 return String.format("%d-Q%d", Integer.valueOf(i), Integer.valueOf((int) Math.ceil((calendar.get(2) + 1) / 3.0d)));
            case "year":
            	return f181c.format(parse);
            case "month":
            	 return f183e.format(parse);
            case "quarter":
                break;
            default:
                return val;
        }
		return val;
    }

    @Override // org.jeecg.modules.online.cgform.converter.FieldCommentConverter
    public Map<String, String> getConfig() {
        return Collections.emptyMap();
    }

    /* compiled from: DateFormatConverter.java */
    /* renamed from: org.jeecg.modules.online.cgform.converter.b.b$a */
    /* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/converter/b/b$a.class */
    static abstract class AbstractC0008a implements InterfaceC0009b {

        /* renamed from: a */
        private final String f188a;

        public AbstractC0008a(String str) {
            this.f188a = str;
        }

        @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
        /* renamed from: b */
        public boolean mo392b(String str) {
            if (null == str || str.isEmpty()) {
                return false;
            }
            return str.matches(this.f188a);
        }
    }

    /* compiled from: DateFormatConverter.java */
    /* renamed from: org.jeecg.modules.online.cgform.converter.b.b$c */
    /* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/converter/b/b$c.class */
    static class C0010c extends AbstractC0008a {

        /* renamed from: a */
        SimpleDateFormat f189a;

        public C0010c(String str, String str2) {
            super(str);
            this.f189a = new SimpleDateFormat(str2);
        }

        @Override // org.jeecg.modules.online.cgform.converter.p011b.DateFormatConverter.InterfaceC0009b
        /* renamed from: a */
        public Date mo391a(String str) throws ParseException {
            return this.f189a.parse(str);
        }
    }
}
